<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Value (computer science)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Value_(computer_science)"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Value_computer_science rootpage-Value_computer_science skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Value (computer science)</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1251242444">
/* start https://en.wikipedia.org/ */
.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style>
<p>In <a href="Computer_science" title="Computer science">computer science</a> and <a href="Software_programming" class="mw-redirect" title="Software programming">software programming</a>, a <b>value</b> is the representation of some entity that can be manipulated by a program. The members of a <a href="Type_(computer_science)" class="mw-redirect" title="Type (computer science)">type</a> are the values of that type.<sup id="cite_ref-FOOTNOTEMitchell19969_1-0" class="reference"><a href="#cite_note-FOOTNOTEMitchell19969-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p><p>The "value of a variable" is given by the corresponding <a href="Map_(computer_science)" class="mw-redirect" title="Map (computer science)">mapping</a> in the <a href="Environment_(type_theory)" class="mw-redirect" title="Environment (type theory)">environment</a>.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> In languages with <a href="Assignable_variable" class="mw-redirect" title="Assignable variable">assignable variables</a>, it becomes necessary to distinguish between the <i>r-value</i> (or contents) and the <i>l-value</i> (or location) of a variable.<sup id="cite_ref-FOOTNOTEMitchell1996389–390_3-0" class="reference"><a href="#cite_note-FOOTNOTEMitchell1996389–390-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup>
</p><p>In <a href="Declarative_programming" title="Declarative programming">declarative</a> (high-level) languages, values have to be <a href="Referential_transparency" title="Referential transparency">referentially transparent</a>. This means that the resulting value is independent of the location of the expression needed to compute the value. Only the contents of the location (the bits, whether they are 1 or 0) and their interpretation are significant.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Value_category">Value category</h2></div>
<p>Despite its name, in the C++ language standards this terminology is used to categorize expressions, not values.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup><sup class="reference nowrap"><span title="Location: 8.2.1">: 8.2.1 </span></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Assignment:_l-values_and_r-values">Assignment: l-values and r-values</h3></div>
<p>Some languages use the idea of <b>l-values</b> and <b>r-values</b>, deriving from the typical mode of evaluation on the left and right-hand side of an assignment statement. An l-value refers to an object that persists beyond a single expression. An r-value is a temporary value that does not persist beyond the expression that uses it.<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup>
</p><p>The notion of l-values and r-values was introduced by <a href="Combined_Programming_Language" class="mw-redirect" title="Combined Programming Language">Combined Programming Language</a> (CPL). The notions in an expression of r-value, l-value, and r-value/l-value are analogous to the <a href="Parameter_(computer_programming)" title="Parameter (computer programming)">parameter</a> modes of input parameter (has a value), <a href="Output_parameter" class="mw-redirect" title="Output parameter">output parameter</a> (can be assigned), and input/output parameter (has a value and can be assigned), though the technical details differ between contexts and languages.
</p>
<div class="mw-heading mw-heading3"><h3 id="R-values_and_addresses">R-values and addresses</h3></div>
<p>In many languages, notably the <a href="C_programming_language" class="mw-redirect" title="C programming language">C family</a>, l-values have <a href="Memory_address" title="Memory address">storage addresses</a> that are programmatically accessible to the running program (e.g., via some address-of operator like "&" in C/C++), meaning that they are variables or <a href="Dereference_operator" class="mw-redirect" title="Dereference operator">de-referenced</a> references to a certain memory location. R-values can be l-values (see below) or non-l-values—a term only used to distinguish from l-values. Consider the C expression <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">4 + 9</code>. When executed, the computer generates an integer value of 13, but because the program has not explicitly designated where in the computer this 13 is stored, the expression is a non l-value. On the other hand, if a C program declares a variable x and assigns the value of 13 to x, then the expression <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">x</code> has a value of 13 and is an l-value.
</p><p>In C, the term l-value originally meant something that could be assigned to (hence the name, indicating it is on the left side of the assignment operator), but since the reserved word <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">const</code> (constant) was added to the language, the term is now 'modifiable l-value'. In <a href="C%2B%2B11" title="C++11">C++11</a> a special semantic-glyph <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">&&</code> exists ( not to be confused with the <code><a href="Short-circuit_evaluation#Support_in_common_programming_languages" title="Short-circuit evaluation">&&</a></code> operator used for logical operations ), to denote the <i>use/access of the expression's address for the </i>compiler<i> only</i>; i.e., the address cannot be retrieved using the address-of <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">&</code> operator during the <i>run-time</i> of the program (see <a href="C%2B%2B11#Rvalue_references_and_move_constructors" title="C++11">the use of move semantics</a>). The addition of move semantics complicated the value classification taxonomy by adding to it the concept of an xvalue (expiring value) which refers to an object near the end of its lifetime whose resources can be reused (typically by moving them). This also lead to the creation of the categories glvalue (generalized lvalue) which are lvalues and xvalues and prvalues (pure rvalues) which are rvalues that are not xvalues.<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup>
</p><p>This type of reference can be applied to <i>all</i> r-values including non-l-values as well as l-values. Some processors provide one or more instructions which take an <b>immediate value</b>, sometimes referred to as "immediate" for short. An immediate value is stored as part of the instruction which employs it, usually to load into, add to, or subtract from, a register. The other parts of the instruction are the <a href="Opcode" title="Opcode">opcode</a>, and destination. The latter may be implicit. (A non-immediate value may reside in a register, or be stored elsewhere in memory, requiring the instruction to contain a direct or indirect address [e.g., index register address] to the value.)
</p><p>The l-value expression designates (refers to) an object. A non-modifiable l-value is addressable, but not assignable. A modifiable l-value allows the designated object to be changed as well as examined. An r-value is any expression, a non-l-value is any expression that is not an l-value. One example is an "immediate value" (see above) and consequently not addressable.
</p>
<div class="mw-heading mw-heading2"><h2 id="In_assembly_language">In assembly language</h2></div>
<p>A value can be virtually any kind of data by a given <a href="Data_type" title="Data type">data type</a>, for instance a string, a digit, a single letter.
</p><p>Processors often support more than one size of immediate data, e.g. 8 or 16 bit, employing a unique opcode and mnemonic for each instruction variant. If a programmer supplies a data value that will not fit, the assembler issues an "Out of range" error message. Most assemblers allow an immediate value to be expressed as <a href="ASCII" title="ASCII">ASCII</a>, <a href="Decimal" title="Decimal">decimal</a>, <a href="Hexadecimal" title="Hexadecimal">hexadecimal</a>, <a href="Octal" title="Octal">octal</a>, or <a href="Binary_code" title="Binary code">binary</a> data. Thus, the ASCII character <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="background:none; border:none; color:inherit; padding: 0px 0px;" dir="ltr">'A'</code> is the same as <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="background:none; border:none; color:inherit; padding: 0px 0px;" dir="ltr">65</code> or <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="background:none; border:none; color:inherit; padding: 0px 0px;" dir="ltr">0x41</code>. The <a href="Byte_order" class="mw-redirect" title="Byte order">byte order</a> of strings may differ between processors, depending on the assembler and computer architecture.
</p>
<div class="mw-heading mw-heading2"><h2 id="Notes">Notes</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */
.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}
/* end https://en.wikipedia.org/ */
</style><div class="reflist reflist-columns references-column-width reflist-columns-2">
<ol class="references">
<li id="cite_note-FOOTNOTEMitchell19969-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEMitchell19969_1-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFMitchell1996">Mitchell 1996</a>, p. 9.</span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFAhoLamSethiUllman1986" class="citation book cs1">Aho, Alfred V.; Lam, Monica S.; Sethi, Ravi; Ullman, Jeffrey D. (1986). <i>Compilers: Principles, Techniques, and Tools</i>. Addison-Wesley Publishing Company. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-201-10088-6</bdi>.</cite></span>
</li>
<li id="cite_note-FOOTNOTEMitchell1996389–390-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEMitchell1996389–390_3-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFMitchell1996">Mitchell 1996</a>, pp. 389–390.</span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.iso.org/standard/68564.html">"ISO/IEC 14882:2017 Programming languages — C++"</a>. 2017.</cite></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://msdn.microsoft.com/en-us/library/f90831hc.aspx">"Lvalues and Rvalues (Visual C++)"</a>. <i>Microsoft Developer Network</i><span class="reference-accessdate">. Retrieved <span class="nowrap">3 September</span> 2016</span>.</cite></span>
</li>
<li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text"><cite id="CITEREFWilliam_M._Miller" class="citation web cs1">William M. Miller. <a rel="nofollow" class="external text" href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3055.pdf">"A Taxonomy of Expression Value Categories"</a> <span class="cs1-format">(PDF)</span>.</cite></span>
</li>
</ol></div>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<ul><li><cite id="CITEREFMitchell1996" class="citation book cs1"><a href="John_C._Mitchell" title="John C. Mitchell">Mitchell, John C.</a> (1996). <i>Foundations for Programming Languages</i>. The MIT Press. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-262-13321-0</bdi>.</cite></li>
<li><cite id="CITEREFStrachey2000" class="citation journal cs1"><a href="Christopher_Strachey" title="Christopher Strachey">Strachey, Christopher</a> (2000). "Fundamental Concepts in Programming Languages". <i><a href="Higher-Order_and_Symbolic_Computation" title="Higher-Order and Symbolic Computation">Higher-Order and Symbolic Computation</a></i>. <b>13</b>: <span class="nowrap">11–</span>49. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1023%2FA%3A1010000313106">10.1023/A:1010000313106</a>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a> <a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:14124601">14124601</a>.</cite></li></ul>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li><a rel="nofollow" class="external text" href="http://c2.com/cgi/wiki?ValueObject">Value Object</a></li>
<li><a rel="nofollow" class="external text" href="http://www.oracle.com/technetwork/java/transferobject-139757.html">Transfer Object Pattern</a></li></ul></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2024-11-28" href="https://en.wikipedia.org/wiki/?title=Value_(computer_science)&oldid=1260010656">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>